package cn.com.fattiger.framework.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * 
 * @author fattiger.xiaoyang
 * @date 2016/04/06
 */
public class CallableDemo {
	public static void main(String[] args){
		ExecutorService es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
		for(int i = 0; i < 10; i++){
			CountHandler handler = new CountHandler(i);
			Future<String> feature = es.submit(handler);
			try {
				System.out.println("task" + i + ": " + feature.get());
			} catch (InterruptedException | ExecutionException e) {
				e.printStackTrace();
			}
		}
		
	}
}

class CountHandler implements Callable<String>{
	
	private int threadNo;
	public CountHandler(int threadNo){
		this.threadNo = threadNo;
	}
	@Override
	public String call() throws Exception {
		System.out.println("线程:" + Thread.currentThread().getName() + "  task:"  + threadNo + "开始工作。");
		return "AAAA" + threadNo;
	}
	
}